﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Credisoft.Models;
using System.Transactions;

namespace Credisoft.Models.Credisoft_DAO
{
    public class CreditGrantingDAO
    {
        public List<otorgamiento> getCreditGrantingData(){
            List<otorgamiento> granting = new List<otorgamiento>();
            using (credisoftEntities bd = new credisoftEntities())
            {
                var encontrado = (from p in bd.otorgamiento
                                  select p).ToList();
                if (encontrado.Count() > 0)
                {
                    foreach (otorgamiento grant in encontrado)
                    {
                        granting.Add(grant);
                    }
                }
            }
            return granting;
        }

        public List<votorgamientosusuario> getGratingByUser()
        {
            using (credisoftEntities bd = new credisoftEntities())
            {
                var encontrado = (from p in bd.votorgamientosusuario
                                  select p).ToList();
                if (encontrado.Count() > 0)
                {
                    return encontrado;
                }
                else
                {
                    return null;
                }
            }
        }

        public otorgamiento insertCreditGranting(otorgamiento solicitud)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (credisoftEntities bd = new credisoftEntities())
                {
                    //bd.otorgamiento.Add(solicitud); // TO DO , HAVE ERRORS
                    //bd.SaveChanges();
                    //transaction.Complete();
                }
            }
            return solicitud;
        }

        public otorgamiento modifyCreditGranting(otorgamiento solicitud)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (credisoftEntities bd = new credisoftEntities())
                {
                    // TO DO
                }
            }
            return solicitud;
        }

        public otorgamientoestacion insertCreditGrantingByStation(otorgamientoestacion solicitudXEstacion)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (credisoftEntities bd = new credisoftEntities())
                {
                    //bd.otorgamientoestacion.Add(solicitudXEstacion); // TO DO : HAVE ERRORS
                    //bd.SaveChanges();
                    //transaction.Complete();
                }
            }
            return solicitudXEstacion;
        }
    }
}